home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / 3d-tools / 3drotate180.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-06  |  4.3 KB  |  166 lines

  1. /*
  2. % 3DROTATE180 - rotate 3D image into another 3D image for displaying
  3. %        and looking from the back toward front.
  4. %
  5. %    Copyright (c)    1991    Jin, Guojun
  6. */
  7. char    usage[]="options\n\
  8. %    Regularly, rotate horizontally to back (along Y axle).    \n\
  9. %    -f #    frame # which begin to process.            \n\
  10. %    -n #    number of frames will be rotated and output.    \n\
  11. %    -r    rolls image along X axle to back.        \n\
  12. %    [<] infile [> [-o] outfile]\n";
  13. /*
  14. @ Improtant Note:
  15. @    MUST include <math.h> in this file
  16. @
  17. @ AUTHOR:    Jin Guojun - LBL    2/14/91
  18. */
  19.  
  20. #include "header.def"
  21. #include "imagedef.h"
  22. #include <math.h>
  23.  
  24. U_IMAGE    uimg;
  25.  
  26. #define    inbuf    uimg.src
  27. #define    obuf    uimg.dest
  28.  
  29.  
  30. main(argc, argv)
  31. int    argc;
  32. char**    argv;
  33. {
  34. /*  !!!    input number is start from 1 and convert to from 0. See line 75    */
  35. MType    bgn_frm=0, frmsNew=0,
  36.     i, f, r, c, fsize;
  37. bool    rolling=0;
  38.  
  39. format_init(&uimg, IMAGE_INIT_TYPE, HIPS, -1, *argv, "S20-1");
  40.  
  41. for (i=1; i<argc; i++)
  42.     if (*argv[i] == '-'){
  43.     c=1;
  44.     switch(argv[i][c++]){
  45.     case 'f':
  46.         bgn_frm = arget(argc,argv,&i,&c);    break;
  47.     case 'n':
  48.         frmsNew = arget(argc,argv,&i,&c);    break;
  49.     case 'r':
  50.         rolling++;    break;
  51.     case 'o':
  52.         if (avset(argc, argv, &i, &c, 1) &&
  53.             (out_fp=freopen(argv[i]+c, "wb", stdout)))    break;
  54.         message("%s can't be opened for write", argv[i]);
  55.     default:
  56. errout:        usage_n_options(usage, i, argv[i]);
  57.     }
  58.     }
  59.     else if ((in_fp=freopen(argv[i], "rb", stdin)) == NULL)
  60.         syserr("input file %s not found", argv[i]);
  61.  
  62. io_test(fileno(in_fp), goto    errout);
  63.  
  64. (*uimg.header_handle)(HEADER_READ, &uimg, 0, 0);
  65. uimg.pxl_out = uimg.pxl_in;
  66. uimg.o_form = uimg.in_form;
  67. fsize = uimg.width * uimg.height;
  68.  
  69. bgn_frm--;
  70. if (bgn_frm<1 || bgn_frm>uimg.frames)    bgn_frm = uimg.frames-1;
  71.  
  72. inbuf = nzalloc(uimg.pxl_in, fsize*uimg.frames, "inbuf");
  73. obuf = nzalloc(uimg.pxl_in, fsize, "obuf");
  74.  
  75. uimg.load_all = uimg.frames;
  76. i = (*uimg.std_swif)(FI_LOAD_FILE, &uimg, 0, No);
  77.  
  78. if (!frmsNew || frmsNew > bgn_frm)    frmsNew = bgn_frm+1;
  79.  
  80. {
  81. char    mesgbuf[1024];
  82.    sprintf(mesgbuf, "%s: start at frame %d (%d frames).    ",
  83.     *argv, bgn_frm+1, frmsNew);
  84.    if (rolling)
  85.     strcat(mesgbuf, "Rolling forward to back\n");
  86.    else    strcat(mesgbuf, "Rotate horizontally to back\n");
  87.    msg("%s\n", mesgbuf);
  88.    (*uimg.header_handle)(ADD_DESC, &uimg, mesgbuf);
  89. }
  90. (*uimg.header_handle)(HEADER_WRITE, &uimg, argc, argv, True);
  91.  
  92. if (rolling)
  93. switch (uimg.pxl_in){
  94. case 1:    {
  95.     register byte    *inbp, *tmpp, *obp;
  96.     for (f=0; f<frmsNew; f++){
  97.         tmpp = (byte*)inbuf;
  98.         tmpp += (bgn_frm-f+1)*fsize - uimg.width;
  99.         obp = (byte*)obuf;
  100.         for (r=0; r < uimg.height; r++, tmpp -= uimg.width)
  101.             for (c=0, inbp=tmpp; c<uimg.width; c++)
  102.             *obp++ = *inbp++;
  103.     if (fwrite(obuf, uimg.pxl_in, fsize, stdout) != fsize)
  104.         syserr("error during B write.");
  105.     }
  106. }break;
  107. case 2:    {
  108.     register short    *inbp, *tmpp, *obp;
  109.     for (f=0; f<frmsNew; f++){
  110.         tmpp = (short*)inbuf;
  111.         tmpp += (bgn_frm-f+1)*fsize - uimg.width;
  112.         obp = (short*)obuf;
  113.         for (r=0; r < uimg.height; r++, tmpp -= uimg.width)
  114.             for (c=0, inbp=tmpp; c<uimg.width; c++)
  115.             *obp++ = *inbp++;
  116.     if (fwrite(obuf, uimg.pxl_in, fsize, stdout) != fsize)
  117.         syserr("error during S write.");
  118.     }
  119. }break;
  120. case 4:    {
  121.     register int    *inbp, *tmpp, *obp;
  122.     for (f=0; f<frmsNew; f++){
  123.         tmpp = (int*)inbuf;
  124.         tmpp += (bgn_frm-f+1)*fsize - uimg.width;
  125.         obp = (int*)obuf;
  126.         for (r=0; r < uimg.height; r++, tmpp -= uimg.width)
  127.             for (c=0, inbp=tmpp; c<uimg.width; c++)
  128.             *obp++ = *inbp++;
  129.     if (fwrite(obuf, uimg.pxl_in, fsize, stdout) != fsize)
  130.         syserr("error during L write.");
  131.     }
  132. }
  133. }
  134. else for (f=0; f<frmsNew; f++){
  135.     switch(uimg.pxl_in){
  136.     case 1:    {
  137.     register byte    *inbp, *obp, *tmpp = (byte*)inbuf;
  138.         tmpp += (bgn_frm-f)*fsize + uimg.width - 1;
  139.         obp = (byte*)obuf;
  140.         for (r=0; r < uimg.height; r++, tmpp += uimg.width)
  141.             for (c=0, inbp=tmpp; c<uimg.width; c++)
  142.             *obp++ = *inbp--;
  143.     }break;
  144.     case 2:    {
  145.     register short    *inbp, *obp, *tmpp = (short*)inbuf;
  146.         tmpp += (bgn_frm-f)*fsize + uimg.width - 1;
  147.         obp = (short*)obuf;
  148.         for (r=0; r < uimg.height; r++, tmpp += uimg.width)
  149.             for (c=0, inbp=tmpp; c<uimg.width; c++)
  150.             *obp++ = *inbp--;
  151.     }break;
  152.     case 4:    {
  153.     register int    *inbp, *obp, *tmpp = (int*)inbuf;
  154.         tmpp += (bgn_frm-f)*fsize + uimg.width - 1;
  155.         obp = (int*)obuf;
  156.         for (r=0; r < uimg.height; r++, tmpp += uimg.width)
  157.             for (c=0, inbp=tmpp; c<uimg.width; c++)
  158.             *obp++ = *inbp--;
  159.     }
  160.     }/* end of switch (uimg.pxl_in)    */
  161.     if (fwrite(obuf, uimg.pxl_in, fsize, stdout) != fsize)
  162.         syserr("error during write.");
  163. }
  164. return(0);
  165. }
  166.